package multiple.dao;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import pojo.Order;
import pojo.User;

import java.util.List;

/**
 * @author Feuler
 * @since 2020/11/10
 **/

public interface OrderMapper {
    /**
     * 查询订单同时查询订单所属用户
     *
     * @return 结果集
     */
    List<Order> findOrderAndUser();


    /**
     * 查询订单同时查询订单所属用户 注解方式
     *
     * @return 结果集
     */
    @Select("select * from `order`")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "orderTime", column = "orderTIme"),
            @Result(property = "total", column = "total"),
            @Result(property = "user", column = "uid", javaType = User.class,
                    one = @One(select = "multiple.dao.UserMapper.findUserById"))
    })
    List<Order> findOrderAndUserWithAnnotation();

    /**
     * 根据用户id查询订单
     *
     * @param uid 用户id
     * @return 结果集
     */
    @Select("select * from `order` where uid = #{uid}")
    List<Order> findOrderByUid(Integer uid);
}
